package rexsee.core.style;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import rexsee.core.browser.Browser;
import rexsee.core.browser.RexseeUrl;
import rexsee.core.browser.clazz.JavascriptInterface;
import rexsee.core.utilities.RexseeClazz;
import rexsee.core.utilities.Utilities;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Environment;
import android.util.TypedValue;

public class RexseeDrawable implements JavascriptInterface {

	public static final String INTERFACE_NAME = "Drawable";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return this;
	}

	public static final HashMap<String, Drawable> mMap = new HashMap<String, Drawable>();

	private final Browser mBrowser;
	private boolean syncTag = false;

	public RexseeDrawable(Browser browser) {
		super();
		mBrowser = browser;
	}

	//JavaScript Interface
	public void add(final String id, final String colorString) {
		remove(id);
		syncTag = false;
		new Thread() {
			@Override
			public void run() {
				Drawable drawable = RexseeDrawable.getDrawable(mBrowser, colorString);
				mMap.put(id, drawable);
				syncTag = true;
			}
		}.start();
		while (!syncTag) {
			try {
				Thread.sleep(100);
			} catch (Exception e) {

			}
		}
		return;
	}
	public void remove(String id) {
		mMap.remove(id);
	}
	public void removeAll() {
		Collection<Drawable> values = mMap.values();
		Iterator<Drawable> iterator = values.iterator();
		while (iterator.hasNext()) {
			Drawable d = iterator.next();
			if (d != null && d instanceof BitmapDrawable) {
				Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
				if (bitmap != null && !bitmap.isRecycled()) bitmap.recycle();
			}
		}
		mMap.clear();
	}
	public boolean exists(String id) {
		return mMap.containsKey(id);
	}
	public int size() {
		return mMap.size();
	}
	public String getIds() {
		String rtn = "";
		Set<String> ids = mMap.keySet();
		Iterator<String> iterator = ids.iterator();
		while (iterator.hasNext()) {
			if (!rtn.equals("")) rtn += ",";
			rtn += "\"" + iterator.next() + "\"";
		}
		return "[" + rtn + "]";
	}

	public String getBounds(String id) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return "";
		Rect rect = drawable.getBounds();
		String rtn = "";
		rtn += "\"top\":" + rect.top;
		rtn += ",\"bottom\":" + rect.bottom;
		rtn += ",\"left\":" + rect.left;
		rtn += ",\"right\":" + rect.right;
		rtn += ",\"centerX\":" + rect.centerX();
		rtn += ",\"centerY\":" + rect.centerY();
		rtn += ",\"width\":" + rect.width();
		rtn += ",\"height\":" + rect.height();
		return "{" + rtn + "}";
	}
	public boolean setBounds(String id, int left, int top, int right, int bottom) {
		final Drawable drawable = mMap.get(id);
		if (drawable == null) return false;
		drawable.setBounds(left, top, right, bottom);
		return true;
	}
	public String getIntrinsicSize(String id) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return "";
		String rtn = "";
		rtn += "\"width\":" + drawable.getIntrinsicWidth();
		rtn += ",\"height\":" + drawable.getIntrinsicHeight();
		return "{" + rtn + "}";
	}
	public boolean setAlpha(String id, int alpha) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return false;
		drawable.setAlpha(alpha);
		return true;
	}
	public boolean setColorFilter(String id, String color, String mode) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return false;
		int c = Color.parseColor(color);
		PorterDuff.Mode m = PorterDuff.Mode.valueOf(mode);
		drawable.setColorFilter(c, m);
		return true;
	}
	public boolean clearColorFilter(String id) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return false;
		drawable.setColorFilter(null);
		return true;
	}

	public boolean clone(String id, String cloneId) {
		Drawable drawable = mMap.get(id);
		if (drawable == null) return false;
		Drawable cloneDrawable = drawable.getConstantState().newDrawable(mBrowser.getResources());
		mMap.remove(cloneId);
		mMap.put(cloneId, cloneDrawable);
		return true;
	}

	public boolean createReflectShader(String id, float reflectHeight) {
		Drawable drawable = createReflectShader(mMap.get(id), reflectHeight);
		if (drawable == null) return false;
		mMap.remove(id);
		mMap.put(id, drawable);
		return true;
	}

	//Static functions

	public static Bitmap drawable2bitmap(Drawable drawable, int w, int h, boolean isHorizontal) {

		if (drawable == null) return null;

		Bitmap bitmap;

		if (drawable instanceof BitmapDrawable) {
			Bitmap oBitmap = ((BitmapDrawable) drawable).getBitmap();
			int newWidth, newHeight;
			if (isHorizontal) {
				float scale = (float) h / (float) oBitmap.getHeight();
				newWidth = (int) (oBitmap.getWidth() * scale);
				newHeight = h;
			} else {
				float scale = (float) w / (float) oBitmap.getWidth();
				newHeight = (int) (oBitmap.getHeight() * scale);
				newWidth = w;
			}
			bitmap = Bitmap.createScaledBitmap(oBitmap, newWidth, newHeight, false);
			oBitmap.recycle();
		} else {
			bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
			Canvas canvas = new Canvas(bitmap);
			drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
			drawable.draw(canvas);
		}

		return bitmap;

	}

	public static Drawable createReflectShader(Drawable drawable, float reflectHeight) {
		if (!(drawable instanceof BitmapDrawable)) return drawable;
		else return new BitmapDrawable(createReflectShader(((BitmapDrawable) drawable).getBitmap(), reflectHeight));
	}
	public static Bitmap createReflectShader(Bitmap bitmap, float reflectHeight) {
		int distance = 4;
		if (bitmap == null) return null;
		if (reflectHeight > 1) reflectHeight = 1;
		if (reflectHeight < 0) reflectHeight = 0;
		try {
			int width = bitmap.getWidth();
			int height = bitmap.getHeight();
			Matrix matrix = new Matrix();
			matrix.preScale(1, -1);
			int rY = Math.round(height * (1 - reflectHeight));
			int rHeight = height - rY;
			Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, rY, width, rHeight, matrix, false);
			Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + rHeight), Config.ARGB_8888);
			Canvas canvas = new Canvas(bitmapWithReflection);
			canvas.drawBitmap(bitmap, 0, 0, null);
			Paint deafaultPaint = new Paint();
			deafaultPaint.setAntiAlias(false);
			canvas.drawBitmap(reflectionImage, 0, height + distance, null);
			Paint paint = new Paint();
			paint.setAntiAlias(false);
			LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + distance, 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
			paint.setShader(shader);
			paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
			canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + distance, paint);
			bitmap.recycle();
			return bitmapWithReflection;
		} catch (Exception e) {
			return bitmap;
		}
	}
	public static Bitmap createReverse(Bitmap bitmap, boolean reverseX, boolean reverseY) {
		if (bitmap == null) return null;
		int width = bitmap.getWidth();
		int height = bitmap.getHeight();
		Matrix matrix = new Matrix();
		if (reverseX && reverseY) {
			matrix.preScale(-1, -1);
		} else if (reverseX) {
			matrix.preScale(-1, 1);
		} else if (reverseY) {
			matrix.preScale(1, -1);
		} else {
			return bitmap;
		}
		return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
	}
	public static Bitmap createAlpha(Bitmap bitmap, int alpha) {
		if (bitmap == null) return null;
		Bitmap rtn = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(rtn);
		Paint paint = new Paint();
		paint.setAlpha(alpha);
		Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		canvas.drawBitmap(bitmap, rect, rect, paint);
		return rtn;
	}
	public static Bitmap createRotate(Bitmap bitmap, int rotation) {
		if (bitmap == null) return null;
		Matrix matrix = new Matrix();
		matrix.setRotate(rotation);
		return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
	}
	public static Bitmap getBoundedBitmap(String path, int bounds) {
		path = Uri.parse(path).getPath();
		if (bounds > 0) {
			try {
				BitmapFactory.Options options = new BitmapFactory.Options();
				options.inJustDecodeBounds = true;
				BitmapFactory.decodeFile(path, options);
				options.inJustDecodeBounds = false;
				options.inSampleSize = Math.max(1, Math.round(Math.max((float) options.outHeight / (float) bounds, (float) options.outWidth / (float) bounds)));
				return BitmapFactory.decodeFile(path, options);
			} catch (Exception e) {
				return null;
			}
		} else {
			return BitmapFactory.decodeFile(path);
		}
	}
	public static Bitmap createBitmapByOrientation(String path) {
		return createBitmapByOrientation(path, -1);
	}
	public static Bitmap createBitmapByOrientation(String path, int bounds) {
		Bitmap bitmap = getBoundedBitmap(path, bounds);
		if (bitmap == null) return null;
		int orientation = getJpegOrientation(path);
		if (orientation == 0) return bitmap;
		Bitmap newBitmap = createRotate(bitmap, orientation);
		if (newBitmap == null) {
			return bitmap;
		} else {
			bitmap.recycle();
			return newBitmap;
		}
	}
	public static Bitmap createBitmapBySpecifiedOrientation(String path, int bounds, int orientation) {
		Bitmap bitmap = getBoundedBitmap(path, bounds);
		if (bitmap == null) return null;
		if (orientation == 0) return bitmap;
		Bitmap newBitmap = createRotate(bitmap, orientation);
		if (newBitmap == null) {
			return bitmap;
		} else {
			bitmap.recycle();
			return newBitmap;
		}
	}
	public static int getJpegOrientation(String photoPath) {
		try {
			ExifInterface exif = new ExifInterface(Uri.parse(photoPath).getPath());
			String o = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
			int orientation = (o == null) ? 1 : Utilities.getInt(o, 1);
			if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
				orientation = 90;
			} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
				orientation = 180;
			} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
				orientation = 270;
			} else {
				orientation = 0;
			};
			return orientation;
		} catch (Exception e) {
			return 0;
		}
	}

	public static Drawable getDrawable(Browser browser, String colorString) {
		return getDrawable(browser.getContext(), browser, colorString);
	}
	public static Drawable getDrawable(Context context, Browser browser, String colorString) {
		Drawable defaultDrawable = new ColorDrawable(Color.TRANSPARENT);
		return getDrawable(context, browser, colorString, defaultDrawable);
	}
	public static Drawable getDrawable(Browser browser, String colorString, Drawable defaultDrawable) {
		return getDrawable(browser.getContext(), browser, colorString, defaultDrawable);
	}
	public static Drawable getDrawable(Context context, Browser browser, String colorString, Drawable defaultDrawable) {
		if (colorString == null) return defaultDrawable;
		colorString = colorString.trim();
		if (colorString.equals("") || colorString.equalsIgnoreCase("default")) return defaultDrawable;
		if (colorString.equalsIgnoreCase("transparent")) return new ColorDrawable(Color.TRANSPARENT);
		Drawable colorDrawable = getColorDrawable(colorString);
		if (colorDrawable != null) return colorDrawable;
		colorString = (browser == null) ? colorString : browser.urlListeners.getAbsoluteUrl(colorString);
		if (colorString.toLowerCase().startsWith("http://") || colorString.toLowerCase().startsWith("https://")) {
			try {
				return Drawable.createFromStream((InputStream) new URL(colorString).getContent(), "src name");
			} catch (Exception e) {
				return defaultDrawable;
			}
		} else if (colorString.toLowerCase().startsWith(RexseeUrl.ASSET_URL)) {
			String imagePath = colorString.replace(RexseeUrl.ASSET_URL, "");
			try {
				return Drawable.createFromResourceStream(context.getResources(), new TypedValue(), context.getResources().getAssets().open(imagePath), null);
			} catch (Exception e) {
				return getAssetDrawable(context, imagePath, defaultDrawable);
			}
		} else if (colorString.toLowerCase().startsWith("file://")) {
			try {
				File file = new File(Uri.parse(colorString).getSchemeSpecificPart());
				if (!file.exists() || !file.isFile() || !file.canRead()) return defaultDrawable;
				return Drawable.createFromPath(file.getAbsolutePath());
			} catch (Exception e) {
				return defaultDrawable;
			}
		} else if (colorString.toLowerCase().startsWith("drawable://")) {
			String id = colorString.substring(11);
			return (mMap.containsKey(id)) ? mMap.get(id) : defaultDrawable;
		} else if (colorString.toLowerCase().startsWith("resource://")) {
			String id = colorString.substring(11);
			return getResourceDrawable(context, id, defaultDrawable);
		} else if (colorString.toLowerCase().startsWith("android://")) {
			String id = colorString.substring(10);
			return getAndroidDrawable(context, id, defaultDrawable);
		} else if (colorString.toLowerCase().startsWith("package://")) {
			return getPackageDrawable(context, colorString, defaultDrawable);
		} else {
			return defaultDrawable;
		}
	}
	public static Drawable getAndroidDrawable(Context context, String rId, Drawable defaultDrawable) {
		try {
			Field field = RexseeClazz.getField(android.R.drawable.class, rId);
			if (field == null) return defaultDrawable;
			int id = field.getInt(null);
			Resources r = context.getResources();
			return r.getDrawable(id);
		} catch (Exception e) {
			return defaultDrawable;
		}
	}
	public static Drawable getResourceDrawable(Context context, String rId, Drawable defaultDrawable) {
		String packageName = context.getPackageName();
		Resources r = context.getResources();
		int id = r.getIdentifier(rId, "drawable", packageName);
		return (id == 0) ? defaultDrawable : r.getDrawable(id);
	}
	public static Drawable getPackageDrawable(Context context, String rId, Drawable defaultDrawable) {
		PackageManager pm = context.getPackageManager();
		if (!rId.startsWith("package://")) return defaultDrawable;
		String packageName = rId.substring("package://".length());
		try {
			return pm.getApplicationIcon(packageName);
		} catch (NameNotFoundException e) {
			return defaultDrawable;
		}
	}

	public static Drawable getAssetDrawable(Context context, String path) {
		String imagePath = path.replace(RexseeUrl.ASSET_URL, "");
		try {
			return Drawable.createFromResourceStream(context.getResources(), new TypedValue(), context.getResources().getAssets().open(imagePath), null);
		} catch (Exception e) {
			return getAssetDrawable(context, imagePath, new ColorDrawable(Color.TRANSPARENT));
		}
	}
	public static Drawable getAssetDrawable(Context context, String path, Drawable defaultDrawable) {
		try {
			if (!(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))) return defaultDrawable;
			int pos = path.lastIndexOf(".");
			if (pos < 0) return defaultDrawable;
			String ext = path.substring(pos);
			String tmpPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmpAssetImage" + ext;
			AssetManager am = context.getResources().getAssets();
			InputStream in = am.open(path);
			if (in == null) return defaultDrawable;
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			byte[] buffer = new byte[1024];
			int len = in.read(buffer);
			while (len >= 0) {
				out.write(buffer, 0, len);
				len = in.read(buffer);
			}
			in.close();
			boolean copy = Utilities.putContent("file://" + tmpPath, out.toByteArray());
			if (!copy) return defaultDrawable;
			return Drawable.createFromPath(tmpPath);
		} catch (Exception e) {
			return defaultDrawable;
		}
	}
	public static Drawable getColorDrawable(String color) {
		if (color == null) return null;
		try {
			String[] parts = color.split("\\/");
			String[] tmp = parts[0].split("\\+");
			int[] colors = new int[tmp.length];
			for (int i = 0; i < tmp.length; i++) {
				String hex = getHexColor(tmp[i]);
				if (hex == null) return null;
				colors[i] = Color.parseColor(hex);
			}
			if (colors.length < 2) {
				return new ColorDrawable(colors[0]);
			} else {
				GradientDrawable.Orientation orientation = (parts.length == 1) ? GradientDrawable.Orientation.TOP_BOTTOM : getGradientOrientation(Utilities.getInt(parts[1], 0));
				return new GradientDrawable(orientation, colors);
			}
		} catch (Exception e) {
			return null;
		}
	}
	public static Bitmap getAssetBitmap(Context context, String path) {
		String imagePath = path.replace(RexseeUrl.ASSET_URL, "");
		Drawable rtn;
		try {
			rtn = Drawable.createFromResourceStream(context.getResources(), new TypedValue(), context.getResources().getAssets().open(imagePath), null);
		} catch (Exception e) {
			rtn = getAssetDrawable(context, imagePath, null);
		}
		if (rtn == null) return null;
		try {
			return ((BitmapDrawable) rtn).getBitmap();
		} catch (Exception e) {
			return null;
		}
	}
	public static GradientDrawable.Orientation getGradientOrientation(int orientation) {
		switch (orientation) {
			case 0 :
				return GradientDrawable.Orientation.TOP_BOTTOM;
			case 1 :
				return GradientDrawable.Orientation.BOTTOM_TOP;
			case 2 :
				return GradientDrawable.Orientation.LEFT_RIGHT;
			case 3 :
				return GradientDrawable.Orientation.RIGHT_LEFT;
			case 4 :
				return GradientDrawable.Orientation.TL_BR;
			case 5 :
				return GradientDrawable.Orientation.BR_TL;
			case 6 :
				return GradientDrawable.Orientation.TR_BL;
			case 7 :
				return GradientDrawable.Orientation.BL_TR;
			default :
				return GradientDrawable.Orientation.TOP_BOTTOM;
		}
	}
	public static int getIntColor(String color) {
		color = color.trim().toLowerCase();
		if (color.equals("transparent")) return Color.TRANSPARENT;
		else return Color.parseColor(getHexColor(color));
	}
	public static String getHexColor(String color) {
		color = color.trim().toLowerCase();
		if (color.startsWith("#")) return color;
		else if (color.equals("aliceblue")) return "#F0F8FF";
		else if (color.equals("antiquewhite")) return "#FAEBD7";
		else if (color.equals("aqua")) return "#00FFFF";
		else if (color.equals("aquamarine")) return "#7FFFD4";
		else if (color.equals("azure")) return "#F0FFFF";
		else if (color.equals("beige")) return "#F5F5DC";
		else if (color.equals("bisque")) return "#FFE4C4";
		else if (color.equals("black")) return "#000000";
		else if (color.equals("blanchedalmond")) return "#FFEBCD";
		else if (color.equals("blue")) return "#0000FF";
		else if (color.equals("blueviolet")) return "#8A2BE2";
		else if (color.equals("brown")) return "#A52A2A";
		else if (color.equals("burlywood")) return "#DEB887";
		else if (color.equals("cadetblue")) return "#5F9EA0";
		else if (color.equals("chartreuse")) return "#7FFF00";
		else if (color.equals("chocolate")) return "#D2691E";
		else if (color.equals("coral")) return "#FF7F50";
		else if (color.equals("cornflowerblue")) return "#6495ED";
		else if (color.equals("cornsilk")) return "#FFF8DC";
		else if (color.equals("crimson")) return "#DC143C";
		else if (color.equals("cyan")) return "#00FFFF";
		else if (color.equals("darkblue")) return "#00008B";
		else if (color.equals("darkcyan")) return "#008B8B";
		else if (color.equals("darkgoldenrod")) return "#B8860B";
		else if (color.equals("darkgray")) return "#A9A9A9";
		else if (color.equals("darkgreen")) return "#006400";
		else if (color.equals("darkkhaki")) return "#BDB76B";
		else if (color.equals("darkmagenta")) return "#8B008B";
		else if (color.equals("darkolivegreen")) return "#556B2F";
		else if (color.equals("darkorange")) return "#FF8C00";
		else if (color.equals("darkorchid")) return "#9932CC";
		else if (color.equals("darkred")) return "#8B0000";
		else if (color.equals("darksalmon")) return "#E9967A";
		else if (color.equals("darkseagreen")) return "#8FBC8B";
		else if (color.equals("darkslateblue")) return "#483D8B";
		else if (color.equals("darkslategray")) return "#2F4F4F";
		else if (color.equals("darkturquoise")) return "#00CED1";
		else if (color.equals("darkviolet")) return "#9400D3";
		else if (color.equals("deeppink")) return "#FF1493";
		else if (color.equals("deepskyblue")) return "#00BFFF";
		else if (color.equals("dimgray")) return "#696969";
		else if (color.equals("dodgerblue")) return "#1E90FF";
		else if (color.equals("firebrick")) return "#B22222";
		else if (color.equals("floralwhite")) return "#FFFAF0";
		else if (color.equals("forestgreen")) return "#228B22";
		else if (color.equals("fuchsia")) return "#FF00FF";
		else if (color.equals("gainsboro")) return "#DCDCDC";
		else if (color.equals("ghostwhite")) return "#F8F8FF";
		else if (color.equals("gold")) return "#FFD700";
		else if (color.equals("goldenrod")) return "#DAA520";
		else if (color.equals("gray")) return "#808080";
		else if (color.equals("green")) return "#008000";
		else if (color.equals("greenyellow")) return "#ADFF2F";
		else if (color.equals("honeydew")) return "#F0FFF0";
		else if (color.equals("hotpink")) return "#FF69B4";
		else if (color.equals("indianred")) return "#CD5C5C";
		else if (color.equals("indigo")) return "#4B0082";
		else if (color.equals("ivory")) return "#FFFFF0";
		else if (color.equals("khaki")) return "#F0E68C";
		else if (color.equals("lavender")) return "#E6E6FA";
		else if (color.equals("lavenderblush")) return "#FFF0F5";
		else if (color.equals("lawngreen")) return "#7CFC00";
		else if (color.equals("lemonchiffon")) return "#FFFACD";
		else if (color.equals("lightblue")) return "#ADD8E6";
		else if (color.equals("lightcoral")) return "#F08080";
		else if (color.equals("lightcyan")) return "#E0FFFF";
		else if (color.equals("lightgoldenrodyellow")) return "#FAFAD2";
		else if (color.equals("lightgreen")) return "#90EE90";
		else if (color.equals("lightgrey")) return "#D3D3D3";
		else if (color.equals("lightpink")) return "#FFB6C1";
		else if (color.equals("lightsalmon")) return "#FFA07A";
		else if (color.equals("lightseagreen")) return "#20B2AA";
		else if (color.equals("lightskyblue")) return "#87CEFA";
		else if (color.equals("lightslategray")) return "#778899";
		else if (color.equals("lightsteelblue")) return "#B0C4DE";
		else if (color.equals("lightyellow")) return "#FFFFE0";
		else if (color.equals("lime")) return "#00FF00";
		else if (color.equals("limegreen")) return "#32CD32";
		else if (color.equals("linen")) return "#FAF0E6";
		else if (color.equals("magenta")) return "#FF00FF";
		else if (color.equals("maroon")) return "#800000";
		else if (color.equals("mediumaquamarine")) return "#66CDAA";
		else if (color.equals("mediumblue")) return "#0000CD";
		else if (color.equals("mediumorchid")) return "#BA55D3";
		else if (color.equals("mediumpurple")) return "#9370DB";
		else if (color.equals("mediumseagreen")) return "#3CB371";
		else if (color.equals("mediumslateblue")) return "#7B68EE";
		else if (color.equals("mediumspringgreen")) return "#00FA9A";
		else if (color.equals("mediumturquoise")) return "#48D1CC";
		else if (color.equals("mediumvioletred")) return "#C71585";
		else if (color.equals("midnightblue")) return "#191970";
		else if (color.equals("mintcream")) return "#F5FFFA";
		else if (color.equals("mistyrose")) return "#FFE4E1";
		else if (color.equals("moccasin")) return "#FFE4B5";
		else if (color.equals("navajowhite")) return "#FFDEAD";
		else if (color.equals("navy")) return "#000080";
		else if (color.equals("oldlace")) return "#FDF5E6";
		else if (color.equals("olive")) return "#808000";
		else if (color.equals("olivedrab")) return "#6B8E23";
		else if (color.equals("orange")) return "#FFA500";
		else if (color.equals("orangered")) return "#FF4500";
		else if (color.equals("orchid")) return "#DA70D6";
		else if (color.equals("palegoldenrod")) return "#EEE8AA";
		else if (color.equals("palegreen")) return "#98FB98";
		else if (color.equals("paleturquoise")) return "#AFEEEE";
		else if (color.equals("palevioletred")) return "#DB7093";
		else if (color.equals("papayawhip")) return "#FFEFD5";
		else if (color.equals("peachpuff")) return "#FFDAB9";
		else if (color.equals("peru")) return "#CD853F";
		else if (color.equals("pink")) return "#FFC0CB";
		else if (color.equals("plum")) return "#DDA0DD";
		else if (color.equals("powderblue")) return "#B0E0E6";
		else if (color.equals("purple")) return "#800080";
		else if (color.equals("red")) return "#FF0000";
		else if (color.equals("rosybrown")) return "#BC8F8F";
		else if (color.equals("royalblue")) return "#4169E1";
		else if (color.equals("saddlebrown")) return "#8B4513";
		else if (color.equals("salmon")) return "#FA8072";
		else if (color.equals("sandybrown")) return "#F4A460";
		else if (color.equals("seagreen")) return "#2E8B57";
		else if (color.equals("seashell")) return "#FFF5EE";
		else if (color.equals("sienna")) return "#A0522D";
		else if (color.equals("silver")) return "#C0C0C0";
		else if (color.equals("skyblue")) return "#87CEEB";
		else if (color.equals("slateblue")) return "#6A5ACD";
		else if (color.equals("slategray")) return "#708090";
		else if (color.equals("snow")) return "#FFFAFA";
		else if (color.equals("springgreen")) return "#00FF7F";
		else if (color.equals("steelblue")) return "#4682B4";
		else if (color.equals("tan")) return "#D2B48C";
		else if (color.equals("teal")) return "#008080";
		else if (color.equals("thistle")) return "#D8BFD8";
		else if (color.equals("tomato")) return "#FF6347";
		else if (color.equals("turquoise")) return "#40E0D0";
		else if (color.equals("violet")) return "#EE82EE";
		else if (color.equals("wheat")) return "#F5DEB3";
		else if (color.equals("white")) return "#FFFFFF";
		else if (color.equals("whitesmoke")) return "#F5F5F5";
		else if (color.equals("yellow")) return "#FFFF00";
		else if (color.equals("yellowgreen")) return "#9ACD32";
		else return null;
	}

}
